package com.xnyzc.lhy.finance.controller.Invoice;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.InvoiceException;
import com.xnyzc.lhy.finance.entity.invoice.response.*;
import com.xnyzc.lhy.finance.entity.params.invoice.InvoiceApplyForDiDiParam;
import com.xnyzc.lhy.finance.entity.params.invoice.InvoiceInvalidDiDiParam;
import com.xnyzc.lhy.finance.entity.params.invoice.InvoiceQueryDiDiParam;
import com.xnyzc.lhy.finance.entity.params.invoice.ResendInvoiceDiDiParam;
import com.xnyzc.lhy.finance.service.invoice.IOaSysInvoiceApplyService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 发票申请 前端控制器
 * </p>
 *
 * @author haoyfa
 * @since 2019-10-24
 */
@Slf4j
@RestController
@RequestMapping("/finance/invoiceapply")
public class OaSysInvoiceApplyController {

    @Autowired
    IOaSysInvoiceApplyService iOaSysInvoiceApplyService;

    @ApiOperation(value = "发票申请", notes = "发票申请")
    @PostMapping(value = "/getInvoiceApplyForDiDi")
    public InvoiceApplyResult getInvoiceApplyForDiDi(@ApiParam(name =
            "invoiceApplyForParam", value = "发票申请") @RequestBody InvoiceApplyForDiDiParam invoiceApplyForDiDiParam) {
        InvoiceApplyResult invoiceApplyResult = null;
        try {
            invoiceApplyResult = iOaSysInvoiceApplyService.getInvoiceApplyForDiDi(invoiceApplyForDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("开发票服务错误");
            invoiceApplyResult = new InvoiceApplyResult();
            invoiceApplyResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceApplyResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceApplyResult;
    }

    @ApiOperation(value = "发票查询", notes = "发票查询")
    @PostMapping(value = "/getInvoiceQueryDiDi")
    public InvoiceQueryResult getInvoiceQueryDiDi(@ApiParam(name =
            "invoiceQueryParam", value = "发票查询") @RequestBody InvoiceQueryDiDiParam invoiceQueryDiDiParam) {


        InvoiceQueryResult invoiceQueryResult = null;
        try {
            invoiceQueryResult = iOaSysInvoiceApplyService.getInvoiceQueryDiDi(invoiceQueryDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("发票查询服务错误");
            invoiceQueryResult = new InvoiceQueryResult();
            invoiceQueryResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceQueryResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceQueryResult;
    }

    @ApiOperation(value = "重发发票", notes = "重发发票")
    @PostMapping(value = "/getResendInvoiceDiDi")
    public InvoiceResendResult getResendInvoiceDiDi(@ApiParam(name =
            "resendInvoiceParam", value = "重发发票") @RequestBody ResendInvoiceDiDiParam resendInvoiceParam) {
        InvoiceResendResult invoiceResendResult = null;
        try {
            invoiceResendResult = iOaSysInvoiceApplyService.getResendInvoiceDiDi(resendInvoiceParam);
        } catch (InvoiceException invoiceException) {
            log.error("发票重发服务错误");
            invoiceResendResult = new InvoiceResendResult();
            invoiceResendResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceResendResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceResendResult;
    }

    @ApiOperation(value = "发票作废", notes = "发票作废")
    @PostMapping(value = "/getInvoiceInvalidDiDi")
    public InvoiceInvalidResult getInvoiceInvalidDiDi(@ApiParam(name =
            "resendInvoiceParam", value = "发票作废") @RequestBody InvoiceInvalidDiDiParam invoiceInvalidDiDiParam) {
        InvoiceInvalidResult invoiceInvalidResult = null;
        try {
            invoiceInvalidResult = iOaSysInvoiceApplyService.getRedInvoiceDiDi(invoiceInvalidDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("发票重发服务错误");
            invoiceInvalidResult = new InvoiceInvalidResult();
            invoiceInvalidResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceInvalidResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceInvalidResult;
    }


    @ApiOperation(value = "AA发票申请", notes = "AA发票申请")
    @PostMapping(value = "/getInvoiceAaApplyForDiDi")
    public InvoiceApplyResult getInvoiceAaApplyForDiDi(@ApiParam(name =
            "invoiceApplyForParam", value = "发票申请") @RequestBody InvoiceApplyForDiDiParam invoiceApplyForDiDiParam) {
        InvoiceApplyResult invoiceApplyResult = null;
        try {
            invoiceApplyResult = iOaSysInvoiceApplyService.getInvoiceAaApplyForDiDi(invoiceApplyForDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("开发票服务异常：{}", invoiceException);
            invoiceApplyResult = new InvoiceApplyResult();
            invoiceApplyResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceApplyResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceApplyResult;
    }

    @ApiOperation(value = "AA发票查询", notes = "AA发票查询")
    @PostMapping(value = "/getInvoiceAaQueryDiDi")
    public InvoiceQueryResult getInvoiceAaQueryDiDi(@ApiParam(name =
            "invoiceQueryParam", value = "发票查询") @RequestBody InvoiceQueryDiDiParam invoiceQueryDiDiParam) {


        InvoiceQueryResult invoiceQueryResult = null;
        try {
            invoiceQueryResult = iOaSysInvoiceApplyService.getInvoiceAaQueryDiDi(invoiceQueryDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("发票查询服务异常：{}", invoiceQueryResult);
            invoiceQueryResult = new InvoiceQueryResult();
            invoiceQueryResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceQueryResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceQueryResult;
    }

    @ApiOperation(value = "AA发票作废", notes = "AA发票作废")
    @PostMapping(value = "/getInvoiceAaInvalidDiDi")
    public InvoiceInvalidResult getInvoiceAaInvalidDiDi(@ApiParam(name =
            "resendInvoiceParam", value = "发票作废") @RequestBody InvoiceInvalidDiDiParam invoiceInvalidDiDiParam) {
        InvoiceInvalidResult invoiceInvalidResult = null;
        try {
            invoiceInvalidResult = iOaSysInvoiceApplyService.getRedInvoiceAaDiDi(invoiceInvalidDiDiParam);
        } catch (InvoiceException invoiceException) {
            log.error("发票作废服务异常：{}", invoiceException);
            invoiceInvalidResult = new InvoiceInvalidResult();
            invoiceInvalidResult.setIsSuccess(false);

            //返回错误信息
            InvoiceErrorResponse invoiceErrorResponse = new InvoiceErrorResponse(
                    invoiceException.getErrno().getDesc(),
                    invoiceException.getErrmsg());
            invoiceInvalidResult.setInvoiceErrorResponse(invoiceErrorResponse);
        }

        return invoiceInvalidResult;
    }

}
